package com.peiqi.aiproject.controller;

import cn.hutool.http.HttpStatus;
import com.peiqi.aiproject.domain.dto.ValidSmsDTO;
import com.peiqi.aiproject.domain.vo.ResponseVO;
import com.peiqi.aiproject.service.SmsService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 短信接口
 */
@RestController
@RequestMapping("/sms")
public class SmsController {
    @Resource
    SmsService smsService;

    /**
     * 发送验证码接口
     * @param phoneNumber 手机号
     * @return code 短信验证码
     */
    @PostMapping
    public ResponseVO<String> sendSms(@RequestBody String phoneNumber){
        String code = smsService.sendSms(phoneNumber);
        return ResponseVO.success(HttpStatus.HTTP_CREATED,code);
    }

    /**
     * 校验短信验证码
     * @param validSmsDTO 验证码校验实体类
     * @return code 短信验证码
     */
    @PostMapping("/valid-sms")
    public ResponseVO<Boolean> validSms(@RequestBody ValidSmsDTO validSmsDTO){
        boolean isValid = smsService.validSms(validSmsDTO);
        return ResponseVO.success(HttpStatus.HTTP_OK,isValid);
    }
}
